home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / STL / Slides / STL10.cp < prev    next >
Text File  |  1998-06-19  |  420b  |  20 lines

  1. // STL10.cp
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string    a = "shared string";
  8.     string    b(a);            // a and b are sharing the same string buffer
  9.  
  10.     if (a[0] != b[0])                    // line 1
  11.     {
  12.         a = b = "un" + a;                // line 2
  13.     }
  14.     if (a.c_str()[0] == b.c_str()[0])    // line 3
  15.     {
  16.         a = b = "un" + a;                // line 4
  17.     }
  18.     // a and b are no longer sharing the same string buffer
  19.     // Question: At what line is the buffer copied?
  20. }